<template>
  <div id="Register">
    <mt-header title="注册">
      <router-link to="/" slot="left">
        <mt-button icon="back">返回</mt-button>
      </router-link>
      <!-- <mt-button icon="more" slot="right"></mt-button> -->
    </mt-header>
    <h2>注册页</h2>
    <hr />

    <!-- <mt-field label="手机号" placeholder="请输入手机号" type="tel" v-model="phone"></mt-field>
        <mt-field label="密码" placeholder="请输入密码" type="password" v-model="password"></mt-field>
        
        <button class="btn" @click="regist()">同意并注册</button> -->

    <van-form @submit="onSubmit">
      <van-field
        v-model="phone"
        name="手机号"
        label="手机号"
        placeholder="请输入手机号"
        :rules="[
          { required: true, message: '请填写手机号' },
          { pattern: /^1[356789]\d{9}$/, message: '手机号格式错误' },
        ]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>
<script>
import url from '../tools/url.js';
import { Toast } from "mint-ui";
export default {
  name: "Register",
  data() {
    return {
      password: "",
      phone: "",
    };
  },
  methods: {
    onSubmit() {
      //发请求
      var str = `phone=${this.phone}&password=${this.password}`;
      this.axios.post(url.REGISTER , str).then((res) => {
        //注册成功跳转到登录页
        if (res.data.code == 200) {
          Toast(res.data.message);
          this.$router.push("/Login");
        } else {
          Toast(res.data.message);
        }
      });
    },
  },
};
</script>
<style scoped>
h2 {
  margin-top: 40px;
}
.btn {
  background: -webkit-linear-gradient(left, #ff9000, #ff5000) no-repeat;
  color: #fff;
  box-shadow: 0 2px 4px #f7c7b1;
  height: 45px;
  border-radius: 35px;
  margin-top: 15px;
  font-size: 16px;
  width: 100%;
  cursor: pointer;
}
</style>
